<?php 
if( !file_exists( './settings.php' ) ) {
	die( "Please create 'settings.php'.\n" );
}

$settings = include( 'settings.php' );

if( !isset( $settings['outputdir'] ) ) {
	die( "No outputdir was specified.\n" );
}

$docs = realpath( dirname( __FILE__ ) . '/../docs' );

$files = glob( $docs . '/*' );

$header = file_get_contents( './templates/header.html' );
$footer = file_get_contents( './templates/footer.html' );

foreach( $files as $file ) {
	echo "Converting " . basename( $file ) . "...\n";
	$html = shell_exec( 'perl ./markdown/Markdown.pl ' . $file );

	file_put_contents(
		$settings['outputdir'] . basename( $file, '.txt' ) . '.html',
		implode( "\n", array( $header, $html, $footer ) )
	);	
}
